<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H+ 后台主题UI框架 - Bootstrap Table</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="/admin/favicon.ico"> <link href="/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/admin/css/animate.css" rel="stylesheet">
    <link href="/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="/admin/js/jquery.min.js?v=2.1.4"></script>
    <style>
        a{
            color:#777;
        }
    </style>

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox-content">
            <div class="row row-lg">
            <div class="col-sm-12">
                <!-- Example Events -->
                <div class="example-wrap">
                    <div class="example">
                        <div class="btn-group hidden-xs" id="tabtar" role="group">
                            <button id='dels' type="button" class="btn btn-warning">
                                <i class="glyphicon glyphicon-trash" aria-hidden="true"></i> 批量删除
                            </button>
                        </div>
                        <table id="table" data-toggle='table' data-height="400">
                            <thead>
                                <tr>
                                    <th data-field="state" data-checkbox="true"></th>
                                    <th data-field="id" data-sortable='true'>ID</th>
                                    <th>用户名</th>
                                    <th>手机</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($arr as $list)
                                <tr>
                                    <td></td>
                                    <td>{{$list->id}}</td>
                                    <td>{{$list->username}}</td>
                                    <td>{{$list->phone}}</td>
                                    <td>
                                        <div class="switch">
                                            <div class="onoffswitch">
                                                <input type="checkbox" @if($list->state==1)checked @endif class="onoffswitch-checkbox" id="bt{{$list->id}}">
                                                <label class="onoffswitch-label" for="bt{{$list->id}}"  onclick="changeState({{$list->id}},this)">
                                                    <span class="onoffswitch-inner"></span>
                                                    <span class="onoffswitch-switch"></span>
                                                </label>
                                            </div>
                                        </div>
                                    </td>
                                    <td>
                                        <a href="javascript:;" class='glyphicon glyphicon-trash del' onclick="del({{$list->id}})" title='删除'></a>
                                    </td>
                                </tr>
                                @endforeach
                                
                            </tbody>
                        </table>
                    </div>
                </div>
                <!-- End Example Events -->
            </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="/admin/js/layer.js"></script>

    <!-- 自定义js -->
    <script src="/admin/js/content.js?v=1.0.0"></script>


    <!-- Bootstrap table -->
    <script src="/admin/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="/admin/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="/admin/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <!-- Peity -->
    <script src="/admin/js/demo/bootstrap-table-demo.js"></script>

    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
    <!--统计代码，可删除-->

    <script>
        // 删除函数
        function del(ids){
            if(typeof ids!='object' & ids!='none'){
                arr=new Array();
                arr[0]=ids.toString(); // 将数字转为数组
                ids=arr;
            }
            if (ids!=='none') {
                layer.confirm('你确定要删除吗？', {
                    btn: ['删除','取消']
                }, function(){
                    // ajax传输数据并响应
                    $.post("/admin/vip/vip_del",{"_method":"DELETE","ids":ids},function(data){
                        if (data == 1) {
                            layer.msg('删除成功', {icon: 1});
                            //删除bt表格中的选中行
                            $('#table').bootstrapTable('remove', {
                                field: 'id',
                                values: ids 
                            });
                        }else{
                            layer.msg('删除失败',{icon: 2});
                        }
                    }).done(function(){
                        $('#table').bootstrapTable('uncheckAll');// 取消选中所有行
                    })
                }, function(){
                    layer.msg('已取消',{icon: 2});
                    $('#table').bootstrapTable('uncheckAll');
                });
            }else{
                layer.msg('未选择数据');
            }
        }
        //删除
        $('#dels').click(function(){
            var idarr=$.map($('#table').bootstrapTable('getSelections'), function (row){
                return row.id;
            }); //获取选中行(数组)
            var ids = $('#table').bootstrapTable('getSelections')[0]?idarr:'none';
            // 调用删除函数
            del(ids);
        });
    </script>

    <script>
        function changeState(id,thiss){
            $.post('/admin/vip/vip_update',{'id':id,'state':'1'},function(data){
                if(data==1){
                    layer.msg('已启用');
                }else{
                    layer.msg('已禁用');
                }
            }).fail(function(){
                layer.msg('出错了');
            })
        }
    </script>

     <script>
        $('#table').bootstrapTable({
            search:true,
            showRefresh:true,
            showColumns:true,
            showToggle:true,
            pagination:true,
            pageSize:'5',
            iconSize:'outline',
            toolbar: '#tabtar',
        });
    </script>

</body>

</html>
